package final2107.day13.jdkproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class TimeAspect implements InvocationHandler {
    //定义变量接受目标对象
    private Object target;
    public TimeAspect(Object target){
        this.target=target;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //获取当前时间
        long t1 = System.currentTimeMillis();
        //执行业务代码
        Object returnVal = method.invoke(target,args);
        //获取当前时间
        long t2 = System.currentTimeMillis();
        System.out.println("耗时："+(t2-t1)+"毫秒");
        return returnVal;
    }
}
